import { Injectable } from '@angular/core';
import { RequestClass } from './request.service';
@Injectable()
export class AddrService {
    constructor(private requestclass: RequestClass) {}
    fetchVillageInfo = async () => {
        return await this.requestclass.request.Pget(
            '/village/getvillagerelationship'
        );
    };

    // 仍在使用的旧接口
    fetchTownInfo = async () => {
        return await this.requestclass.request.Pget(
            '/town/gettownrelationship'
        );
    };

    fetchCityInfo = async () => {
        return await this.requestclass.request.Pget('/city/getcityinfo');
    };

    fetchDistrictInfo = async () => {
        return await this.requestclass.request.Pget(
            '/district/getdistrictrelationship'
        );
    };

    fetchAreaInfo = async () => {
        return await this.requestclass.request.Pget(
            '/area/getarearelationship'
        );
    };

    fetchDistrictList = async () => {
        return await this.requestclass.request.Pget(
            '/district/getdistrictinfo'
        );
    };

    fetchAreaList = async () => {
        return await this.requestclass.request.Pget('/area/getareainfo');
    };

    fetchTownList = async () => {
        return await this.requestclass.request.Pget('/town/gettowninfo');
    };

    fetchVillageList = async () => {
        return await this.requestclass.request.Pget('/village/getvillageinfo');
    };

    AddVillageInfoByConfig = async ({ townId, villageName, address }) => {
        return await this.requestclass.request.post(
            '/village/insertvillageinfo',
            {
                data: {
                    villageName,
                    address,
                    townId,
                },
            }
        );
    };

    editDistrictInfoByConfig = async ({ cityId, districtId, districtName }) => {
        return await this.requestclass.request.put(
            '/district/updatedistrictinfo',
            {
                data: {
                    cityId,
                    districtId,
                    districtName,
                },
            }
        );
    };

    editVillageInfoByConfig = async ({
        address,
        townId,
        villageId,
        villageName,
    }) => {
        return await this.requestclass.request.put(
            '/village/updatevillageinfo',
            {
                data: {
                    address,
                    townId,
                    villageId,
                    villageName,
                },
            }
        );
    };

    AddTownInfoByConfig = async ({ districtId, townName }) => {
        return await this.requestclass.request.post('/town/inserttowninfo', {
            data: {
                districtId,
                townName,
            },
        });
    };

    AddCityInfoByConfig = async ({ cityId, cityName }) => {
        return await this.requestclass.request.post('/city/insertcityinfo', {
            data: {
                cityId,
                cityName,
            },
        });
    };

    AddDistrictInfoByConfig = async ({ cityId, districtName }) => {
        return await this.requestclass.request.post(
            '/district/insertdistrictinfo',
            {
                data: {
                    cityId,
                    districtName,
                },
            }
        );
    };

    AddAreaInfoByConfig = async ({ address, areaName }) => {
        return await this.requestclass.request.post('/area/insertareainfo', {
            data: {
                address,
                areaName,
            },
        });
    };

    editCityInfoByConfig = async ({ cityId, cityName }) => {
        return await this.requestclass.request.put('/city/updatecityinfo', {
            data: {
                cityId,
                cityName,
            },
        });
    };

    editTownInfoByConfig = async ({ districtId, townId, townName }) => {
        return await this.requestclass.request.put('/town/updatetowninfo', {
            data: {
                districtId,
                townId,
                townName,
            },
        });
    };

    editAreaInfoByConfig = async ({ address, areaId, areaName }) => {
        return await this.requestclass.request.put('/area/updateareainfo', {
            data: {
                address,
                areaId,
                areaName,
            },
        });
    };

    deleteDistrictInfoById = async ({ id }) => {
        return await this.requestclass.request.delete(
            '/district/deletedistrictinfo',
            {
                params: {
                    districtId: id,
                },
            }
        );
    };

    deleteAreaInfoById = async ({ id }) => {
        return await this.requestclass.request.delete('/area/deleteareainfo', {
            params: {
                areaId: id,
            },
        });
    };

    deleteTownInfoById = async ({ id }) => {
        return await this.requestclass.request.delete('/town/deletetowninfo', {
            params: {
                townId: id,
            },
        });
    };

    deleteVillageInfoById = async ({ id }) => {
        return await this.requestclass.request.delete(
            '/village/deletevillageinfo',
            {
                params: {
                    villageId: id,
                },
            }
        );
    };

    deleteCityInfoById = async ({ id }) => {
        return await this.requestclass.request.delete('/city/deletecityinfo', {
            params: {
                cityId: id,
            },
        });
    };
}
